<?php

/*
 * Create by Indonesian Brain Solutions
 * E-mail : cs@mesinit.com
 * Programmer : sony@sonywibisono.com
 */
if (!defined('__BACKEND__'))
    die("you cannot directly access this page");

include("class/Tickets.php");

_showMenuHeader();

function add(){
    global $user_id;
    $tanggal=date('Y-m-d');
    $select_priority=  select_priority(0);
    $select_request_type=  select_request_type(0);
    $select_location=  select_site_location(0, 0);
    echo "<div id=\"table_data\"><h2>Create Ticket</h2>
        <form action=\"?mod=ticket\" method=\"post\">    
    <input type=\"hidden\" name=\"action\" value=\"add_process\"/>
    <input type=\"hidden\" name=\"user_create_id\" value=\"$user_id\"/>
        <input type=\"hidden\" name=\"ticket_status_type_id\" value=\"1\"/>
<table cellpadding=\"4\" cellspacing=\"0\">
 
<tr><td class=\"field_name\">Ticket Date</td><td class=\"field_object\">
<input type=\"text\" name=\"ticket_date\" class=\"textbox\" rel=\"tanggal\" value=\"$tanggal\"/> </td></tr> 
<tr><td class=\"field_name\">Subject</td><td class=\"field_object\">
<input type=\"text\" name=\"subject\" class=\"textbox\" size='50'/> </td></tr>
<tr><td class=\"field_name\">Description</td><td class=\"field_object\">
<textarea name=\"description\" cols=\"50\" rows='15'/></textarea> </td></tr>
<tr><td class=\"field_name\">Priority</td><td class=\"field_object\">
$select_priority </td></tr>
<tr><td class=\"field_name\">Request Type</td><td class=\"field_object\">
$select_request_type</td></tr>
<tr><td class=\"field_name\">Location Id</td><td class=\"field_object\">
$select_location </td></tr>
<tr><td></td><td><input class=\"button\" type=\"submit\" value=\"Add Ticket\"/>
        <input class=\"button\" type=\"button\" name=\"cancel\" 
        value=\"Cancel\" onclick=\"javascript:history.go(-1);\"/></td></tr></table></form>
    </div>";
}
function edit(){
    global $db,$id;
    if(!empty($id)){
    $sql="select * from";
    $row=$db->fetch_row($sql);
    extract($row);
    $select_priority=  select_priority($priority_id);
    $select_request_type=  select_request_type($request_type_id);
    $select_location=  select_site_location($customerid, $location_id);
    echo "<h2>Edit Record</h2><form action=\"?mod=ticket\" method=\"post\">    
    <input type=\"hidden\" name=\"action\" value=\"add_process\"/>
<table cellpadding=\"4\" cellspacing=\"0\">
<tr><td class=\"field_name\">Id</td><td class=\"field_object\"><input type=\"text\" name=\"id\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Ticket Date</td><td class=\"field_object\"><input type=\"text\" name=\"ticket_date\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">First Response</td><td class=\"field_object\"><input type=\"text\" name=\"first_response\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Close Date</td><td class=\"field_object\"><input type=\"text\" name=\"close_date\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Subject</td><td class=\"field_object\"><input type=\"text\" name=\"subject\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Description</td><td class=\"field_object\"><input type=\"text\" name=\"description\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Due Date</td><td class=\"field_object\"><input type=\"text\" name=\"due_date\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">User Create Id</td><td class=\"field_object\"><input type=\"text\" name=\"user_create_id\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Priority Id</td><td class=\"field_object\"><input type=\"text\" name=\"priority_id\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Request Type Id</td><td class=\"field_object\"><input type=\"text\" name=\"request_type_id\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Location Id</td><td class=\"field_object\"><input type=\"text\" name=\"location_id\" class=\"textbox\"/> </td></tr>
<tr><td class=\"field_name\">Ticket Status Type Id</td><td class=\"field_object\"><input type=\"text\" name=\"ticket_status_type_id\" class=\"textbox\"/> </td></tr>
<tr><td></td><td><input class=\"button\" type=\"submit\" value=\"Kirim\"/>
        <input class=\"button\" type=\"button\" name=\"cancel\" 
        value=\"Cancel\" onclick=\"javascript:history.go(-1);\"/></td></tr></table></form>";
    }
}
function add_process(){
    global $db,$id,$mod,$ticket_date,$first_response,$close_date,$subject,
            $description,$due_date,$user_create_id,$priority_id,$request_type_id,
            $location_id,$ticket_status_type_id;
    if (!empty($subject)){
    //echo "Add Process Record";
    $ticket=new Tickets();
    $ticket->ticket_date=$ticket_date;
    $ticket->first_response=$first_response;
    $ticket->close_date=$close_date;
    $ticket->subject=$subject;
    $ticket->description=$description;
    $ticket->due_date=$due_date;
    $ticket->user_create_id=$user_create_id;
    $ticket->priority_id=$priority_id;
    $ticket->request_type_id=$request_type_id;
    $ticket->location_id=$location_id;
    $ticket->ticket_status_type_id=$ticket_status_type_id;
    $ticket->insert();
    $url="?mod=$mod";
    $msg="Add New Record Success";
    refresh_to($url, $msg, 2);
    }
}
function edit_process(){
    global $db,$id,$mod,$file,$ticket_date,$first_response,$close_date,$subject,$description,$due_date,$user_create_id,$priority_id,$request_type_id,$location_id,$ticket_status_type_id;
    if (!empty($id)){
    //echo "Add Process Record";
    $ticket=new Tickets();
    $ticket->ticket_date=$ticket_date;
    $ticket->first_response=$first_response;
    $ticket->close_date=$close_date;
    $ticket->subject=$subject;
    $ticket->description=$description;
    $ticket->due_date=$due_date;
    $ticket->user_create_id=$user_create_id;
    $ticket->priority_id=$priority_id;
    $ticket->request_type_id=$request_type_id;
    $ticket->location_id=$location_id;
    $ticket->ticket_status_type_id=$ticket_status_type_id;
    $ticket->update(); 
    $url="?mod=$mod";
    $msg="Update Record Success";
    refresh_to($url, $msg, 2);
    }
}
function delete_process(){
    global $db,$id,$mod,$file;
    if (!empty($id)){
    echo "Delete Process Record";
    $url="?mod=$mod&file=$file";
    $msg="Delete Record Success";
    $sql="delete from app_menus where id=$id";
    $db->query($sql);
    refresh_to($url, $msg, 2);
    }
}
function __default(){
    global $db,$page,$sortby,$sortorder,$mod,$pagesize,$file;
    if (empty($page)){
        $start=0;
        $sql="select a.*,b.title from app_menus a,app_modules b
            where a.module_id=b.id order by caption";
    } else {
        $start=$page*$pagesize;
        $sql="select a.*,b.title from app_menus a,app_modules b
            where a.module_id=b.id order by caption limit $start,$pagesize";
    }
   
    
    $query=$db->query($sql);
    echo "<h2>Application Menu List</h2>
        <div id=\"caption_table\"><a href=\"?mod=$mod&file=menus&action=add\">Add New</a></div>";
    echo "<div id=\"table_data\"><table width=\"100%\" cellpadding=2 cellspacing=0>
        <tr><th class='table_left_top'>Id</th><th>Caption</th><th>Tool Tips</th><th>Grant Admin</th>
        <th>Enabled</th><th>Icon Url</th><th>Filename</th><th>Module</th><th class='table_right_top'>Action</th></tr>";
    while ($row=$db->fetch_array($query)){
        extract($row);
        echo "<tr><td>$id</td><td>$caption</td><td>$tool_tips</td><td>$grant_admin</td>
            <td>$enabled</td><td>$icon_url</td><td>$filename</td><td>$title</td>
                <td align=center><a href=\"?mod=$mod&file=$file&action=edit&id=$id\" class=\"icon_link\">
                    <img class='icon_small' src='images/edit.png' title='Edit'/></a>
        <a href=\"?mod=$mod&file=$file&action=delete&id=$id\" class=\"icon_link\">
            <img class='icon_small' src='images/delete.png' title='Delete'/></a></td></tr>";
    }
    echo "<tr class='row_odd'><td class=\"table_left_bottom\"></td>
        <td colspan='5'>&nbsp;</td><td class=\"table_right_bottom\"></td></tr>";
    echo "</table></div>";
}
global $action,$user_id,$login_status,$is_admin,$mod;
switch($action){
    case 'add':
        add();
        break;
    case 'edit':
        edit();
        break;
    case 'add_process':
        add_process();
        break;
    case 'edit_process':
        edit_process();
        break;
    case 'delete':
        delete_process();
        break;
    default:
        add();
}
?>